package org.cshoo.sys.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.adobe.cairngorm.view.ViewLocator;
	
	import mx.controls.Alert;
	import mx.rpc.IResponder;
	import mx.rpc.events.ResultEvent;
	
	import org.cshoo.sys.business.DictionaryDelegate;
	import org.cshoo.sys.event.FindDictionaryListEvent;
	import org.cshoo.sys.model.SysModelLocator;
	import org.cshoo.sys.model.vo.Dictionary;
	
	public class FindDictionaryListCommand implements ICommand, IResponder
	{
		
		private var _model:SysModelLocator = SysModelLocator.getInstance();		
		
		public function execute(event:CairngormEvent):void
		{
			var dictionary:Dictionary = (event as FindDictionaryListEvent).dictionary;
			var firstResult:Number = (event as FindDictionaryListEvent).firstResult;
			var maxResults:Number = (event as FindDictionaryListEvent).maxResults;
			var dictionaryDelegate:DictionaryDelegate = new DictionaryDelegate(this);
			dictionaryDelegate.findDictionaryBatcheArrayByExample(dictionary,firstResult,maxResults);
		}
		
		public function result(event:Object):void
		{
			var collection:Array = (event as ResultEvent).result as Array;
			_model.dictionaryCollectionTotalRecord = collection[0];
			_model.dictionaryCollection = collection[1];
		}
		
		public function fault(info:Object):void
		{
			Alert.show("无法连接");
		}
	}
}